<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");
include_once(__DBConnect_File);

$intLID = (int)$_data["LID"];
$intUpDateTime = (int)$_data["UpDateTime"];
if($intUpDateTime <= 0)$intUpDateTime = -1;

$strCon = "";

$strSQL = "select * from `bet_TodayGame".$intLID."` where `UpdateTime` > ".$intUpDateTime." order by GambleID, Bet_Type, Number";

if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Data Error";
	$GLOBALS["errorhidden"] = "\nError: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;

	$strCon = "<table>\n<tr><td>".$GLOBALS["errormessage"]."</td><td>".$GLOBALS["errorhidden"]."</td></tr></table>";
	WebOutputHTML($strCon, 1);
}

$arrRow = array();
$intGID = 0;
while($objRows = PMA_mysql_fetch_object($RS)){
	$arrRow[$objRows -> Bet_Type][$objRows -> Number] = $objRows;
	$intGID = $objRows -> GambleID;
}

$strSQL = "select * from `bet_RealTodayGame".$intLID."` where `UserID` = 0 and `GambleID` = ".$intGID." order by Bet_Type, Number";
if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Data Error";
	$GLOBALS["errorhidden"] = "\nError: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;

	$strCon = "<table>\n<tr><td>".$GLOBALS["errormessage"]."</td><td>".$GLOBALS["errorhidden"]."</td></tr></table>";
	WebOutputHTML($strCon, 1);
}
$arrRealRow = array();
while($objRealRows = PMA_mysql_fetch_object($RS)){
	$arrRealRow[$objRealRows -> Bet_Type][$objRealRows -> Number] = $objRealRows;
}

$arrBT = array(51 => 4, 52 => 10, 53 => 13,
						 54 => 3, 55 => 9, 56 => 12,
						 57 => 2, 58 => 8, 59 => 11,
						 60 => 22, 61 => 26, 62 => 17, 63 => 18,
						 64 => 7, 65 => 6, 66 => 5, 67 => 23,
						 68 => 24, 69 => 29, 70 => 30, 71 => 31, 72 => 32,
						 73 => 33, 74 => 34, 75 => 35, 76 => 36, 77 => 37,
						 78 => 999, 79 => 999, 80 => 999, 81 => 999, 82 => 999, 83 => 999, 
						 84 => 16, 85 => 15, 86 => 14, 
						 87 => 19, 88 => 20, 89 => 21,
						 90 => 27, 91 => 28, 92 => 1, 93 => 25
						 );//

asort($arrBT);
foreach($arrBT as $intBT => $intSNo){
	if($intSNo == 999 || $intSNo == null)continue;

	$arrTmp = $arrRow[$intBT];
	if(!is_array($arrTmp))continue;
	if(sizeof($arrTmp) == 0)continue;

	foreach($arrTmp as $intNum => $objRows){
		$arrN = array("", "", "");

		$intN1 = floor($intNum / 100);
		$intN2 = floor(($intNum % 100) / 10);
		$intN3 = $intNum % 10;
		$intSameType = 1;
		switch($intBT){
			case 92:
			case 93:
				if($intN1 == $intN2 && $intN1 == $intN3)$intSameType = 3;
				elseif($intN1 != $intN2 && $intN1 != $intN3 && $intN2 != $intN3)$intSameType = 1;
				else $intSameType = 2;

				$arrN = array($intN1, $intN2, $intN3);
				break;

			case 64:
			case 65:
			case 66:
			case 67:
				if($intN2 == $intN3)$intSameType = 2;
				$arrN = array(floor($intNum / 10), $intNum % 10, "");
				break;

			default:
				$arrN[0] = $intNum;
				break;
		}
		$strCon .= "<tr><td>".$intBT."</td><td>".$arrN[0]."</td><td>".$arrN[1]."</td><td>".$arrN[2]."</td><td>".$intSameType."</td><td>".$objRows -> Odds."</td><td>".($objRows -> tolRealStake - tolSuppleStake)."</td><td>".($objRows -> tolRealPayOff - tolSupplePayOff)."</td><td>".($objRows -> tolCommission - tolSuppleCommission)."</td><td>".$objRows -> tolWager."</td><td>".$objRows -> isStopBet."</td></tr>\n";
	}
}


//=======================================================
//組三 組六拆號碼的資料
$arrExtraBT = array(
						 69 => 2, 70 => 2, 71 => 2, 72 => 2,
						 73 => 3, 74 => 3, 75 => 3, 76 => 3, 77 => 3
						 );
$arrExtraNum = array();
$arrExtraNum[2] =  array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89);
$arrExtraNum[3] =  array( 12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67, 68, 69, 78, 79, 89, 123, 124, 125, 126, 127, 128, 129, 134, 135, 136, 137, 138, 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168, 169, 178, 179, 189, 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249, 256, 257, 258, 259, 267, 268, 269, 278, 279, 289, 345, 346, 347, 348, 349, 356, 357, 358, 359, 367, 368, 369, 378, 379, 389, 456, 457, 458, 459, 467, 468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789 );

foreach($arrExtraBT as $intBT => $intSNo){

	$arrTmp = $arrRealRow[$intBT];
	foreach($arrExtraNum[$intSNo] as $intNum){
		$objRows = $arrTmp[$intNum];

		$arrN = array("", "", "");

		$intN1 = floor($intNum / 100);
		$intN2 = floor(($intNum % 100) / 10);
		$intN3 = $intNum % 10;
		$intSameType = 999;
		switch($intSNo){
			case 3:
				$arrN = array($intN1, $intN2, $intN3);
				break;

			default:
				$arrN = array($intN2, $intN3, "");
				break;
		}
		$strCon .= "<tr><td>".$intBT."</td><td>".$arrN[0]."</td><td>".$arrN[1]."</td><td>".$arrN[2]."</td><td>".$intSameType."</td><td>NA</td><td>".($objRows -> tolRealStake - tolSuppleStake)."</td><td>".($objRows -> tolRealPayOff - tolSupplePayOff)."</td><td>".($objRows -> tolCommission - tolSuppleCommission)."</td><td>".($objRows -> tolWager*1)."</td><td>NA</td></tr>\n";
	}
}


$strCon = "<tr><td>BT(".date("H:i:s").")</td><td>Num1</td><td>Num2</td><td>Num3</td><td>Same Num</td><td>Odds</td><td>Stake</td><td>PayOff</td><td>Commission</td><td>Wager No</td><td>isStop</td></tr>\n".$strCon;
$strCon = "<table border=1>\n".$strCon."</table>";
//輸出
WebOutputHTML($strCon, 1);
?>